package what.basic.collection;

import java.util.concurrent.DelayQueue;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

public class delayedreminder implements Delayed{
	private String remindertext;
	private long delayinseconds;
	public delayedreminder(String reminder,long seconds){
		remindertext=reminder;
		delayinseconds=seconds;
	}
	public String getremindertext(){
		return remindertext;
	}
	public static void main(String[] args) {
		DelayQueue<delayedreminder> queue=new DelayQueue<delayedreminder>();
		delayedreminder reminder=new delayedreminder("wake me up in 6 seconds",100);
		System.out.println("wake me up in 100 seconds");
		queue.add(reminder);
		reminder=new delayedreminder("wake me up in 30 seconds",30);
		System.out.println("wake me up in 30 seconds");
		queue.add(reminder);
	}
	public int compareTo(Delayed o) {
		return (int)(delayinseconds-o.getDelay(TimeUnit.SECONDS));
	}
	@Override
	public long getDelay(TimeUnit unit) {
		return TimeUnit.SECONDS.convert(delayinseconds, unit);// TODO Auto-generated method stub
	}

}
